﻿using System;

//自定义命名空间
using BasicUtility = DreamCube.Foundation.Basic.Utility;
using RemotingFramework = DreamCube.Framework.Utilities.Remoting;

namespace BGN.PlugIn.Client
{
    /// <summary>
    /// 管理remoting的类
    /// </summary>
    public static class RemotingService
    {
        private static BGN.Common.Remoting.SystemConnection sysConn; //系统连接

        /// <summary>
        /// 启动remoting事件
        /// </summary>
        public static void Start()
        {
            try
            {
                Int32 port = 0;
                if (Int32.TryParse(CommonConfiger.Instance.GetActiveXToBGNRemotingPort(), out port))
                {
                    //sinfo插件充当客户端，布谷鸟充当服务器端
                    //sinfo不断尝试连接布谷鸟客户端
                    RemotingFramework.Server.Instance.InitialServer(port, "SisenSinfoActiveX");

                    //注册远程通信对象
                    sysConn = new BGN.Common.Remoting.SystemConnection();
                    sysConn.ClientConnect += new BGN.Common.Remoting.SystemConnection.ClientConnectHandler(sysConn_ClientConnect);
                    RemotingFramework.Server.Instance.RegisterRemotingObjByInstance(sysConn);
                }
            }
            catch (Exception ex)
            {
                BasicUtility.MyLog.MakeLog(ex);
            }
        }

        //当客户端连接上来，就触发一个连接事件
        static void sysConn_ClientConnect()
        {
            IEWinHelper.OnClientConnect();
        }
    }
}
